package tests.jdl.databaseObjects;

import java.io.File;
import java.io.IOException;

import jdl.databaseObjects.Database;
import jdl.databaseObjects.ObjectAlreadyExistsException;
import jdl.databaseObjects.Table;
import jdl.databaseObjects.TableCollection;
import junit.framework.Assert;

import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class Database_Test {
	private Database database;
	private File testFolder;

	@Before
	public void setUp() throws IOException {
		testFolder = new File("tests");
		FileUtils.deleteDirectory(testFolder);
		testFolder.mkdir();
	}

	@After
	public void tearDown() throws IOException {
		FileUtils.deleteDirectory(testFolder);
	}

	@Test
	public void addTable() throws ObjectAlreadyExistsException {
		database = new Database("qwerty");
		Table table = new Table("Cpp");
		database.addTable(table);
		TableCollection collection = database.getTableCollection();
		Assert.assertEquals(1, collection.getCount());
		Assert.assertEquals(table, collection.getObjectByIndex(0));
	}
}
